# Contributor: André Klitzing <aklitzing@gmail.com>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Andy Postnikov <apostnikov@gmail.com>
pkgname=unit-php84
pkgver=1.33.0
pkgrel=1
pkgdesc="PHP 8.4 module for NGINX Unit"
url="https://unit.nginx.org/"
arch="all"
license="Apache-2.0"
_phpver=84
depends="unit"
makedepends="
	linux-headers
	openssl-dev>3
	php$_phpver-dev
	php$_phpver-embed
	"
checkdepends="procps-ng
	py3-openssl
	py3-pytest
	php$_phpver-opcache
	"
#source="https://unit.nginx.org/download/unit-$pkgver.tar.gz"
source="unit-$pkgver.tar.gz::https://github.com/nginx/unit/archive/refs/tags/$pkgver.tar.gz"
builddir="$srcdir/unit-$pkgver"

build() {
	./configure \
		--prefix="/usr" \
		--localstatedir="/var" \
		--runstatedir="/run" \
		--statedir="/var/lib/unit" \
		--control="unix:/run/control.unit.sock" \
		--pid="/run/unit.pid" \
		--log="/var/log/unit.log" \
		--tmpdir=/tmp \
		--modulesdir="/usr/lib/unit/modules" \
		--openssl \
		--user=unit \
		--group=unit \
		--tests
	./configure php --module=php$_phpver --config=php-config$_phpver --lib-path=/usr/lib/php84

	make
	make php$_phpver tests
}

check() {
	# FIXME: some tests fail in CI or locally in checkroot too
	local _fds=160 # fds leaking in tests
	local _allow_fail=no
	case "$CARCH" in
		armhf | armv7) _allow_fail=yes ;; # segfault
	esac
	pytest test --fds-threshold=$_fds -k "
		test_php \
		and not test_php_isolation \
		and not test_php_application_forbidden \
		and not test_php_application_shared_opcache \
	" || [ "$_allow_fail" = yes ]
}

package() {
	make php$_phpver-install DESTDIR="$pkgdir"
}

sha512sums="
2135fc9f6b1ae6e764c7da770e1a924cd8223f6a042229ac41cf84086f748e11503ad2bf84684dc0f141bcc1846b8fec7d03df49129a63df930d14c8afec98aa  unit-1.33.0.tar.gz
"
